package com.cn.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.cn.cloud.entities.CommonResult;
import com.cn.cloud.entities.People;
import com.cn.service.DtgxPeopleService;
import com.cn.service.PeopleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/dtgx/people")
public class DtgxPeopleController {

    @Autowired
    private DtgxPeopleService dtgxPeopleService;
    @Autowired
    private PeopleService peopleService;


    @Value("${server.port}")
    private String SERVER_PORT;

    @PostMapping("/create")
    @SentinelResource("create")
    public CommonResult create(@RequestBody People people) {
        int result = peopleService.create(people);
        log.info("插入数据的ID:\t" + people.getId());
        log.info("插入结果：" + result);
        if (result > 0) {
            return new CommonResult(200, "插入数据成功,serverport:" + SERVER_PORT);
        } else {
            return new CommonResult(444, "插入数据失败", null);
        }
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        System.out.println("11111111111111111111111");
        return dtgxPeopleService.getPeopleById(id);
    }


}
